

import {HashRouter as Hash,BrowserRouter as History , useRoutes, Navigate} from "react-router-dom"



import {lazy,Suspense } from "react"  //路由懒加载
import Loading from "../components/Loading"  //组件loading 引入
import ErrorRoute from "./Errors/route"
import MainRoute from "./Mains/route"
import LoginRoute from "./Logins/route"
import SeacrchRoute from "./Search/route"
import GoodRoute from "./Good/route"
import CartRoute from "./Cart/route"
import MineRoute from "./Mine/route"
 
// 路由懒加载 （闪屏效果 -> 页面渲染数据多时会出现）
const Demo = lazy(()=>import("./Demo/Demo"))  
const Guide = lazy(()=>import("./Guide/Guide")) 
export default function MainRouter(){
    return(
        <History>
             {/* 懒加载 */}
            <Suspense  fallback={ <Loading/>}>   
            <NewRouter></NewRouter>
            </Suspense>
            
        </History>
    )
}

function NewRouter(){
    const routes:any =[
        {
            // 重定向
            path:"/",
            element:<Navigate replace to={"/guide"}/>
        },
        {
            path:"/guide",
            element:<Guide/>
        },{
            path:"/demo",
            element:<Demo/>
        },
        ...MainRoute,
        ...ErrorRoute,
        ...LoginRoute,
        ...SeacrchRoute,
        ...GoodRoute,
        ...CartRoute,
        ...MineRoute,
        {
            // 重定向
            path:"*",  
            element:<Navigate replace to={"/404"}/>
        }
    
    ]
    return useRoutes(routes)
}